package cn.jy.careuplusdoctor.mycenter;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import cn.jy.careuplusdoctor.R;
import cn.jy.careuplusdoctor.base.BaseActivity;
import cn.jy.careuplusdoctor.injector.IdInject;
import cn.jy.careuplusdoctor.main.LoginActivity;
import cn.jy.careuplusdoctor.utils.CheckNewVersion;
import cn.jy.careuplusdoctor.widgets.CareuTitleBar.TitleBarLeftAction;

public class MyCenterActiyity extends BaseActivity implements
		TitleBarLeftAction {
	// 版本号
	@IdInject(id = R.id.txt_versions)
	private TextView	txt_versions;
	/*// 个人信息
	@IdInject(id = R.id.ll_personage)
	private LinearLayout	ll_personage;
	// 修改密码
	@IdInject(id = R.id.ll_reset_passwor)
	private LinearLayout	ll_reset_passwor;
	// 意见反馈
	@IdInject(id = R.id.ll_feedback)
	private LinearLayout	ll_feedback;
	// 注销登陆 
	@IdInject(id = R.id.btn_logout)
	private Button	btn_logout;*/
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_my_center);
		initTitleBar();
		onInJectView();
		txt_versions.setText("慢糖生活·医v"+CheckNewVersion.getVersionName(this));
	}

	@Override
	protected void settingTitleBar() {
		super.settingTitleBar();
		getTitleBar().setLeftText("全部患者");
		getTitleBar().setTitle("更多");
		getTitleBar().setLeftAction(this);
		getTitleBar().getLeftImageView().setImageResource(R.drawable.title_bar_back);
		getTitleBar().getRightView().setVisibility(View.GONE);
	}

	@Override
	protected void onAfterInJector() {
		super.onAfterInJector();
		OnClickListener listener = new OnClickListener() {
			@Override
			public void onClick(View v) {
				switch (v.getId()) {
					case R.id.ll_personage:
						openActivity(MineInfoActivity.class);
						break;
					case R.id.ll_reset_passwor:
						openActivity(ResetPasswordActivity.class);
						break;
					case R.id.ll_feedback:
						updateDialog().show();
						break;
					case R.id.btn_logout:
						MyCenterActiyity.this.getSharedPreferences("careu_doctor", Context.MODE_PRIVATE).edit().clear()
						.commit();
						openActivity(LoginActivity.class);
						defaultFinish();
						break;
				}
			}
		};
		findViewById(R.id.ll_personage).setOnClickListener(listener);
		findViewById(R.id.ll_reset_passwor).setOnClickListener(listener);
		findViewById(R.id.ll_feedback).setOnClickListener(listener);
		findViewById(R.id.btn_logout).setOnClickListener(listener);
	}
	@Override
	public void onLeftPress(View view) {
		defaultFinish();
	}
	public AlertDialog updateDialog() {
		AlertDialog.Builder builder = new Builder(MyCenterActiyity.this);
		builder.setTitle("意见反馈");
		builder.setMessage("请加入QQ群：339477649反馈您的宝贵意见");
		DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener()  
	    {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				dialog.dismiss();
			}  
	    };
		builder.setPositiveButton("知道了", listener);
		AlertDialog alert = builder.create();
		alert.setCanceledOnTouchOutside(false);
		alert.show();
		return alert;
	}
}
